#! /usr/bin/env python
# -*- coding: utf-8 -*-

import json


def main():
    dict1 = {'id': '1', "name": '张三'}
    print(json.dumps(dict1))
    print(json.dumps(dict1, ensure_ascii=False))
    print("====================================")
    testConvert()

def testConvert():
    """
    测试
    :return:
    """
    # python对象转json字符串
    dict1 = {"aa": "哈哈", "bb": "嘻嘻"}
    list1 = [1, 2, 3, 4, 5, 6, "中国"]
    tuple1 = (1, 2, 3, "中国")

    json_str = json.dumps(dict1, ensure_ascii=False)
    print("json_str=", json_str)
    json_obj = json.loads(json_str)
    print("json_obj=", json_obj)
    print(json_obj["aa"])

    # 构造字典
    jsonMap = {}
    jsonMap["testData"] = dict1
    print(json.dumps(jsonMap, ensure_ascii=False))

if __name__ == '__main__':
    main()
